from src.core.utils.date_time import get_date_time
from src.database.uow import SQLAlchemyUoW


class StatsService:
    def __init__(self, uow: SQLAlchemyUoW):
        self._uow = uow

    async def add_stats(
        self,
        products_purchased: int = 0,
        orders_created: int = 0,
        users_registered: int = 0,
        payments_payed: int = 0,
    ) -> None:
        """Обновляем/создаем статистику за текущий день"""

        date = get_date_time().replace(hour=0).replace(minute=0).replace(second=0)

        await self._uow.stats_repo.add_or_update_stats(
            date,
            products_purchased,
            orders_created,
            users_registered,
            payments_payed,
        )

        await self._uow.commit()
